<template>
  <div class="home">
    <div class="index-search-box">
      <div class="search-main flex-box">
        <input type="text" @click="toSearch" class="search" placeholder="搜索专家问题">
        <span> <svg class="icon" aria-hidden="true"><use xlink:href="#icon-wenzheng-iconfonticonfontsousuo1"></use></svg></span>
      </div>
    </div>
    <div class="top-banner">
      <div class="top-banner-main">
        <swiper :options="swiperBanner" id="swiper-banner" ref="mySwiperBanner">
          <swiper-slide class="flex-box">
            <p class="ani-a ani" swiper-animate-effect="fadeInLeft" swiper-animate-duration="0.35s" swiper-animate-delay="0.15s">华大基因旗下</p>
            <p class="ani-b ani" swiper-animate-effect="fadeInLeft" swiper-animate-duration="0.35s" swiper-animate-delay="0.25s">善问医生-专家问诊</p>
            <p class="ani-c ani" swiper-animate-effect="fadeInLeft" swiper-animate-duration="0.35s" swiper-animate-delay="0.35s">在线问诊免排队，医生快速回答</p>
            <img src="../assets/img/banner-a02.png" alt="">
          </swiper-slide>
          <swiper-slide class="flex-box">
            <p class="ani-a ani-a1 ani" swiper-animate-effect="fadeInLeft" swiper-animate-duration="0.35s" swiper-animate-delay="0.15s">华大基因旗下</p>
            <p class="ani-b ani" swiper-animate-effect="fadeInLeft" swiper-animate-duration="0.35s" swiper-animate-delay="0.25s">善问医生-悬赏提问</p>
            <p class="ani-c ani" swiper-animate-effect="fadeInLeft" swiper-animate-duration="0.35s" swiper-animate-delay="0.35s">悬赏提问快速解答</p>
            <img src="../assets/img/banner-a03.png" alt="">
          </swiper-slide>
        </swiper>
      </div>
      <div class="nav-list">
        <ul class="flex-box">
          <li v-for="(item, index) in listNavs" :key="index" @click="$router.push(item.link)">
            <img :src="require('../assets/img/'+ item.img)">
            <p>{{item.title}}</p>
          </li>
        </ul>
      </div>
    </div>
    <ZhuanJia :listZjPost="listZj" :titleShow="isTitle"></ZhuanJia>
    <JieDaNav></JieDaNav>
    <div class="answer-box">
      <!-- <keep-alive><JieDaMain :postJiedaLists = jieDaLists></JieDaMain></keep-alive> -->
      <JieDaMain :checkAllState = true :initState = navIndex :postJiedaLists = jieDaData></JieDaMain>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import * as swiperAni from '@/quanjiyin/assets/js/common/swiper.animate.min'
import '../assets/js/iconfont-wenzheng'
import ZhuanJia from '../components/IndexZhuanJia.vue'
import JieDaNav from '../components/IndexJieDaNav.vue'
import JieDaMain from '../components/IndexJieDaMain.vue'
export default {
  name: 'home',
  data() {
    return {
      navIndex: 0,
      isTitle: true,
      listZj: [
        {
          img: 'tx-a001.jpg',
          name: '侯永平',
          desc: '深圳红十字会医院儿科主治',
          price: '20元提问'
        },
        {
          img: 'tx-a001.jpg',
          name: '侯永平',
          desc: '深圳红十字会医院儿科主治',
          price: '20元提问'
        },
        {
          img: 'tx-a001.jpg',
          name: '侯永平',
          desc: '深圳红十字会医院儿科主治',
          price: '20元提问'
        },
        {
          img: 'tx-a001.jpg',
          name: '侯永平',
          desc: '深圳红十字会医院儿科主治',
          price: '20元提问'
        }
      ],
      listNavs: [
        {
          img: 'sw-icon-a01.png',
          title: '专家问诊',
          link: '/zhuanjia'
        },
        {
          img: 'sw-icon-a02.png',
          title: '悬赏提问',
          link: '/askpay'
        },
        {
          img: 'sw-icon-a03.png',
          title: '专家回答',
          link: '/answer'
        },
        {
          img: 'sw-icon-a04.png',
          title: '悬赏回答',
          link: '/answer'
        }
      ],
      showComponents: true,
      bannerIndex: 0,
      slidesNavIndex: 1,
      jieDaData: {
        jieDaLists: '',
        checkAllShow: true,
        loadingShow: true,
        noDataShow: false
      },
      swiperBanner: {
        // resistanceRatio: 0, // 禁止边缘抵抗
        effect: 'fade',
        speed: 1500,
        autoplay: {
          delay: 3500,
          stopOnLastSlide: false,
          disableOnInteraction: false
        },
        on: {
          init: function() {
            swiperAni.swiperAnimateCache(this)
            swiperAni.swiperAnimate(this)
          },
          slideChange: function() {
            swiperAni.swiperAnimate(this)
          }
        }
      }
    }
  },
  components: {
    ZhuanJia,
    JieDaNav,
    JieDaMain
  },
  computed: {
    mySwiperBanner() {
      return this.$refs.mySwiperBanner.swiper
    }
  },
  methods: {
    getJiaDa(page) {
      this.$axios
        .get('./data/shanwen-data/jieda-a0' + page + '.json')
        .then(res => {
          // console.log(res.data.resule)
          // res.data.result.forEach(function(item, index) {
          //   return index < 5
          // })
          // console.log(res.data.result)
          this.jieDaData.jieDaLists = res.data.result.slice(0, 4)
          this.jieDaData.loadingShow = false
          this.jieDaData.noDataShow = false
          if (!res.data.result.length) {
            this.jieDaData.noDataShow = true
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    toSearch() {
      this.$router.push('/search')
    }
  },
  created() {
    this.$bus.$on('jieDaNavIndex', data => {
      this.jieDaData.loadingShow = true
      this.jieDaData.noDataShow = false
      this.jieDaData.jieDaLists = ''
      this.navIndex = data
      setTimeout(() => {
        this.getJiaDa(data + 1)
      }, 1000)
    })
    this.$navigation.on('back', () => {
      this.$bus.$emit('setNavIndex', 0)
      this.getJiaDa(1)
      this.jieDaData.noDataShow = false
    })
  },
  mounted() {
    this.getJiaDa(1)
  }
}
</script>
<style lang="scss" scoped>
.home {
  width: 100%;
  text-align: left;
  background: #fff;
  padding-bottom: 50px;
  .index-search-box {
    max-width: 750px;
    margin: 0 auto;
    height: 55px;
    background: #f7f7f7;
    .search-main {
      width: 100%;
      height: 100%;
      position: relative;
      span {
        position: absolute;
        left: 24px;
        top: 18px;
        font-size: 18px;
        color: #ccc;
      }
      input {
        width: 355px;
        height: 35px;
        box-sizing: border-box;
        padding-left: 40px;
        padding-right: 10px;
        background: #fff;
        border-radius: 40px;
        outline: none;
        border: 1px solid #eee;
        color: #999;
        font-size: 14px;
        -webkit-appearance: none;
      }
      ::-webkit-input-placeholder {
        /* WebKit, Blink, Edge */
        color: #ccc;
      }
      :-ms-input-placeholder {
        /* Internet Explorer 10-11 */
        color: #ccc;
      }
    }
  }
  .top-banner {
    max-width: 750px;
    margin: 0 auto;
    border-top: 1px solid #eee;
    padding-left: 10px;
    padding-right: 10px;
    padding-top: 10px;
    border-bottom: #f7f7f7 10px solid;
    .top-banner-main {
      width: 100%;
      position: relative;
      padding-bottom: 34%;
      // overflow: hidden;
      // background: rgba($color: #000000, $alpha: 0.11px;
      .swiper-container {
        width: 100%;
        height: 100%;
        overflow: inherit;
        position: absolute;
        top: 0;
        left: 0;
        .swiper-slide {
          width: 100%;
          height: 100%;
          flex-wrap: wrap;
          background-size: 100%;
          -webkit-flex-wrap: wrap;
          img {
            width: 100%;
            height: 100%;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba($color: #000000, $alpha: 0.1);
          }
          h4 {
            font-family: 'FZZZHONGJW';
            color: #fff;
            width: 100%;
            font-size: 24px;
            text-align: center;
            line-height: 36px;
          }
          .add-botton {
            width: 126px;
            height: 34px;
            margin: 0 auto;
            background: #fff;
            border-radius: 100px;
            margin-top: 12px;
            box-shadow: 0 4px 8px rgba($color: #000000, $alpha: 0.05);
            span {
              float: left;
              font-size: 26px;
              color: #5baef6;
              margin-top: 4px;
              margin-left: 12px;
              margin-right: 6px;
            }
            p {
              line-height: 34px;
              color: #6dbbfe;
              font-size: 16px;
            }
          }
          p {
            position: absolute;
            left: 10px;
            color: #fff;
            z-index: 6;
            &.ani-a {
              top: 15px;
              font-size: 12px;
              padding: 6px 12px;
              border-radius: 50px;
              background: #3389f2;
            }
            &.ani-a1 {
              background: #00a184;
            }
            &.ani-b {
              top: 50px;
              font-size: 22px;
              line-height: 26px;
              font-family: 'FZZCHJW';
            }
            &.ani-c {
              top: 87px;
              font-size: 11px;
              line-height: 14px;
            }
          }
        }
      }
    }
    .nav-list {
      width: 100%;
      text-align: center;
      margin-top: 20px;
      margin-bottom: 10px;
      position: relative;
      ul {
        width: 100%;
        justify-content: space-between;
        padding-left: 14px;
        padding-right: 14px;
        box-sizing: border-box;
        li {
          display: inline-block;
          color: #999999;
          font-size: 19px;
          line-height: 26px;
          img {
            width: 40px;
          }
          p {
            font-size: 12px;
            line-height: 18px;
            margin-bottom: 2px;
          }
        }
      }
      .nav-line {
        width: 44px;
        height: 2px;
        position: absolute;
        bottom: -10px;
        left: -200px;
        background: #000;
        transition: all 0.25s ease;
        -webkit-transition: all 0.25s ease;
      }
    }
  }
}
.answer-box {
  height: 400px;
  overflow-y: auto;
}
</style>
